package com.ruoyi.bizsys.service.impl;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.bizsys.vo.WalletAmountVo;
import com.ruoyi.common.utils.DateUtils;
            import org.springframework.stereotype.Service;
    import com.ruoyi.bizsys.mapper.WalletAmountMapper;
import com.ruoyi.bizsys.domain.WalletAmount;
import com.ruoyi.bizsys.service.IWalletAmountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 钱包账户金额Service业务层处理
 *
 * @author african-loan
 * @date 2022-06-17
 */
@Service
public class WalletAmountServiceImpl extends ServiceImpl<WalletAmountMapper,WalletAmount> implements IWalletAmountService {

    /**
     * 查询钱包账户金额
     *
     * @param id 钱包账户金额ID
     * @return 钱包账户金额
     */
    @Override
    public WalletAmount selectWalletAmountById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询钱包账户金额列表
     *
     * @param walletAmount 钱包账户金额
     * @return 钱包账户金额
     */
    @Override
    public List<WalletAmount> selectWalletAmountList(WalletAmount walletAmount) {
        return this.list(new QueryWrapper<>(walletAmount).last("order by id desc"));
    }

    /**
     * 新增钱包账户金额
     *
     * @param walletAmount 钱包账户金额
     * @return 结果
     */
            @Override
    public int insertWalletAmount(WalletAmount walletAmount) {
                                                                                                                                                                                                                        walletAmount.setCreateTime(DateUtils.getNowDate());
                                                                    return baseMapper.insert(walletAmount);
    }

    /**
     * 修改钱包账户金额
     *
     * @param walletAmount 钱包账户金额
     * @return 结果
     */
            @Override
    public int updateWalletAmount(WalletAmount walletAmount) {
                                                                                                                                                                                                                                                                walletAmount.setUpdateTime(DateUtils.getNowDate());
                            return baseMapper.updateById(walletAmount);
    }

    /**
     * 批量删除钱包账户金额
     *
     * @param ids 需要删除的钱包账户金额ID
     * @return 结果
     */
            @Override
    public int deleteWalletAmountByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除钱包账户金额信息
     *
     * @param id 钱包账户金额ID
     * @return 结果
     */
    @Override
    public int deleteWalletAmountById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public BigDecimal selectWalletAmount(String custNo) {
        return baseMapper.selectWalletAmount(custNo);
    }

    @Override
    public WalletAmountVo selectWalletLisDetail(WalletAmount walletAmount) {

        WalletAmountVo wallet = baseMapper.selectWalletLisDetail(walletAmount);
        WalletAmountVo walletAmountVo = new WalletAmountVo();
        walletAmountVo.setTotalAmount(wallet.getTotalAmount().setScale(2, BigDecimal.ROUND_UP));
        walletAmountVo.setAvailableBalance(wallet.getAvailableBalance().setScale(2, BigDecimal.ROUND_UP));
        walletAmountVo.setAvailableBonus(wallet.getAvailableBonus().setScale(2, BigDecimal.ROUND_UP));
        walletAmountVo.setFrozenBalance(wallet.getFrozenBalance().setScale(2, BigDecimal.ROUND_UP));
        walletAmountVo.setFrozenBonus(wallet.getFrozenBonus().setScale(2, BigDecimal.ROUND_UP));
        walletAmountVo.setBalance(wallet.getBalance().setScale(2, BigDecimal.ROUND_UP));
        walletAmountVo.setBonus(wallet.getBonus().setScale(2, BigDecimal.ROUND_UP));
        walletAmountVo.setWalletStatus(wallet.getWalletStatus());
        return walletAmountVo;
    }

}
